<?php
set_include_path(
	realpath( dirname(__FILE__) . "/../public/js" )
	. PATH_SEPARATOR
	. get_include_path()
);

if ( isset($_GET['test']) ) {
	$test = $_GET['test'];
	require "nrgut/{$test}/{$test}.js";
}
else {
	$Di = new DirectoryIterator( dirname(__FILE__) . "/../public/js/nrgut" );
	
	$to_require = array();
	
	foreach ( $Di as $File ) {
		if ( $File->isDot() ) {
			continue;
		}
		
		if ( $File->isDir() ) {
			$SubDi = new DirectoryIterator( $File->getPathname() );
			foreach ( $SubDi as $SubFile ) {
				if ( $SubFile->isDot() || $SubFile->isDir() ) {
					continue;
				}
				
				$pathinfo = pathinfo( $SubFile->getPathname() );
				if ( empty($pathinfo['extension']) ) {
					continue;
				}
				
				if ( 'js' == $pathinfo['extension'] ) {
					$to_require[] = $SubFile->getPathname();
				}
			}
		}
	}
	
	sort($to_require);
	
	foreach ( $to_require as $req ) {
		require_once $req;
	}
	
	//echo '<pre>' . print_r($to_require, true) . '</pre>';
}
?>